<?php

$onload = " onload=\"document.SearchForm.searchstring.focus()\" ";

$cbSoundsLike = @$_POST['cbSoundsLike'];
$cbFirstName = @$_POST['cbFirstName'];
$cbSurname = @$_POST['cbSurname'];
$cbShortName = @$_POST['cbShortName'];
$cbStreetName = @$_POST['cbStreetName'];
$cbSuburb = @$_POST['cbSuburb'];

$cbPhoneNumber = @$_POST['cbPhoneNumber'];
$cbFaxNumber = @$_POST['cbFaxNumber'];
$cbComments = @$_POST['cbComments'];
$cbworktype = @$_POST['cbworktype'];
$searchstring = trim(@$_POST['searchstring']);
$PHPSESSID = @$_SESSION['PHPSESSID'];
$checked = ' checked="checked" ';

/*
echo "<pre>";
print_r($_SERVER  $HTTP_SERVER_VARS);
echo "</pre>";
*/

?>


<div id="page_header">
    <ul><li class="titlename2">Search</li>
        <li class="type2">Part of database to specifically search</li>
    </ul>
</div>
<div id="main_content">
    <form method="post" id="MainSearchForm" action="index.php?view=Find&amp;PHPSESSID=<?php echo $PHPSESSID; ?>" >
        <table border="0" cellspacing="2" width="100%">
            <tr>
                <td valign="top">
                    <input type="text" name="searchstring" size="35" value="<?php echo $searchstring ?>" class="mediumtxtInput" />
                    &nbsp;
                    <input type="submit" value="Submit" class="smalltxtInput" />
                    <br />Use 'sounds like' search <input type="checkbox" name="cbSoundsLike" <?php if (!is_null($cbSoundsLike) and strlen($searchstring)>0) {echo  $checked ;} ?> />
                    <p class="smalltxt">Use % character as wildcard<br />
                    E.g. 'j% bloggs' will return Joe Bloggs, John Bloggs, Jane Bloggs etc.</p>

                </td>
                <td><table border="0" width="100%">
                        <tr>
                            <td colspan="2" style="text-align:center"><input id="z" type="checkbox" name="cbALL"
                                                                                 <?php if (is_null($cbSurname) AND is_null($cbStreetName) AND is_null($cbFirstName) AND is_null($cbSuburb) AND is_null($cbShortName)  AND is_null($cbPhoneNumber) AND is_null($cbFaxNumber) AND is_null($cbComments) AND is_null($cbworktype) ) {echo  $checked ;} ?>

                                                                                 onclick="uncheckCheckBox('cbSurname','cbSurname','cbStreetName');uncheckCheckBox('cbFirstName','cbFirstName','cbSuburb');uncheckCheckBox('cbShortName','cbShortName','');uncheckCheckBox('cbPhoneNumber','cbPhoneNumber','cbFaxNumber');uncheckCheckBox('cbComments','cbComments','cbworktype');"
                                                                                 />ALL
                            </td>
                        </tr>
                        <tr>
                            <td><input id="a" type="checkbox" name="cbSurname" <?php if (!is_null($cbSurname)) {echo  $checked ;} ?> onclick="uncheckCheckBox('cbALL','cbALL','');" />Surname</td>
                            <td><input id="b" type="checkbox" name="cbStreetName" <?php if (!is_null($cbStreetName)) {echo  $checked ;} ?> onclick="uncheckCheckBox('cbALL','cbALL','');" />Street Name</td>
                        </tr><tr>
                            <td><input id="c" type="checkbox" name="cbFirstName" <?php if (!is_null($cbFirstName)) {echo  $checked ;} ?> onclick="uncheckCheckBox('cbALL','cbALL','');" />Firstname</td>
                            <td><input id="d" type="checkbox" name="cbSuburb" <?php if (!is_null($cbSuburb)) {echo  $checked ;} ?> onclick="uncheckCheckBox('cbALL','cbALL','');" />Suburb</td>
                        </tr><tr>
                            <td><input id="e" type="checkbox" name="cbShortName" <?php if (!is_null($cbShortName)) {echo  $checked ;} ?> onclick="uncheckCheckBox('cbALL','cbALL','');" />ShortName</td>
                            <td><input id="j" type="checkbox" name="cbworktype" <?php if (!is_null($cbworktype)) {echo  $checked ;} ?> onclick="uncheckCheckBox('cbALL','cbALL','');" />Work Type</td>
                        </tr>
                        <tr>
                            <td><input id="g" type="checkbox" name="cbPhoneNumber" <?php if (!is_null($cbPhoneNumber)) {echo  $checked ;} ?> onclick="uncheckCheckBox('cbALL','cbALL','');" />Phone Number</td>
                            <td><input id="h" type="checkbox" name="cbFaxNumber" <?php if (!is_null($cbFaxNumber)) {echo  $checked ;} ?> onclick="uncheckCheckBox('cbALL','cbALL','');" />Fax Number</td>
                        </tr>
                        <tr>
                            <td><input id="i" type="checkbox" name="cbComments" <?php if (!is_null($cbComments)) {echo  $checked ;} ?> onclick="uncheckCheckBox('cbALL','cbALL','');" />Comments</td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </form>
</div>
<?php

if ($searchstring)
{
/*
    echo "searchtype = ".$searchtype."<br />";
    echo "searchstring = ".$searchstring."<p>";
    echo "Surname = ".$cbSurname."<br />";
    echo "FirstName = ".$cbFirstName."<br />";
    echo "ShortName = ".$cbShortName."<br />";
    echo "StreetName = ".$cbStreetName."<br />";
    echo "Suburb = ".$cbSuburb."<br />";
    echo "Email = ".$cbEmail."<br />";
    echo "Suburb = ".$cbSuburb."<br />";
*/

    // setup for soundex compare

    $StrSoundEx = "";
    $StrWildcard = "%";
    $StrLikeValue = "'$StrWildcard$searchstring$StrWildcard'";
    $StrLikeValue = str_replace(" ",$StrWildcard,$StrLikeValue);
    //	$StrLikeValue = "'$searchstring'";

    if (!is_null($cbSoundsLike))
    {
        $StrSoundEx = "SOUNDEX";
        $StrWildcard = "";
        $StrLikeValue = "$StrSoundEx('$searchstring')";
    }
    $strWhere = "0"; // string to build WHERE clause


    if (!is_null($cbSurname))
    {
        // insert Like string for this variable
        $strWhere = $strWhere." OR $StrSoundEx(Upper(Surname)) LIKE Upper($StrLikeValue)";
        $strWhere .= "\n";
    }
    if (!is_null($cbFirstName))
    {
        // insert Like string for this variable
        $strWhere = $strWhere." OR $StrSoundEx(Upper(FirstName)) LIKE Upper($StrLikeValue)";
        $strWhere .= "\n";
    }

    if (!is_null($cbSurname))
    {
        // insert Like string for this variable
        $strWhere = $strWhere." OR $StrSoundEx(Upper(Surname)) LIKE Upper($StrLikeValue)";
        $strWhere .= "\n";
    }
    if (!is_null($cbFirstName))
    {
        // insert Like string for this variable
        $strWhere = $strWhere." OR $StrSoundEx(Upper(FirstName)) LIKE Upper($StrLikeValue)";
        $strWhere .= "\n";
    }


    if (!is_null($cbSurname) &&     (!is_null($cbFirstName)))
    {
        // insert Like string for this variable
        $strWhere = $strWhere." OR $StrSoundEx(Upper(Upper(CONCAT(FirstName,' ' ,Surname)))) LIKE Upper($StrLikeValue)";
        $strWhere .= "\n";
    }
    if (!is_null($cbStreetName))
    {
        // insert Like string for this variable
        $strWhere = $strWhere." OR $StrSoundEx(Upper(ResidentialStreetName)) LIKE Upper($StrLikeValue) OR $StrSoundEx(Upper(PostalAddressLine1)) LIKE Upper($StrLikeValue) OR $StrSoundEx(PostalAddressLine2) LIKE $StrLikeValue";
        $strWhere .= "\n";
    }
    if (!is_null($cbSuburb))
    {
        // insert Like string for this variable
        $strWhere = $strWhere." OR $StrSoundEx(Upper(ResidentialSuburb)) LIKE Upper($StrLikeValue) OR $StrSoundEx(Upper(PostalAddressSuburb)) LIKE Upper($StrLikeValue)";
        $strWhere .= "\n";
    }

    if (!is_null($cbPhoneNumber))
    {
        // insert Like string for this variable
        $strWhere = $strWhere." OR $StrSoundEx(HomePhoneNumber) LIKE $StrLikeValue OR $StrSoundEx(WorkPhoneNumber) LIKE $StrLikeValue";
        $strWhere .= "\n";
    }

    if (!is_null($cbFaxNumber))
    {
        // insert Like string for this variable
        $strWhere = $strWhere." OR $StrSoundEx(HomeFaxNumber) LIKE $StrLikeValue OR $StrSoundEx(WorkFaxNumber) LIKE $StrLikeValue";
        $strWhere .= "\n";
    }
    if (!is_null($cbComments))
    {
        // insert Like string for this variable
        $strWhere = $strWhere." OR $StrSoundEx($PACTS_cfg->individualtablename.CommentText) LIKE $StrLikeValue OR $StrSoundEx($PACTS_cfg->familytablename.CommentText) LIKE $StrLikeValue";
        $strWhere .= "\n";
    }
    if (!is_null($cbworktype))
    {
        // insert Like string for this variable
        $strWhere = $strWhere." OR $StrSoundEx(Upper(".$PACTS_cfg->worktypetablename.".Description)) LIKE Upper($StrLikeValue)";
        $strWhere .= "\n";
    }

    if (trim($strWhere) == "0") {
        // set search for all fields
        $strWhere = "0 OR $StrSoundEx(Concat(Upper(FirstName), ' ', Upper(Surname))) LIKE Upper($StrLikeValue) OR $StrSoundEx(Upper(Surname)) LIKE Upper($StrLikeValue) ";
        $strWhere .= "\n";
        $strWhere = $strWhere."OR $StrSoundEx(Upper(FirstName)) LIKE Upper($StrLikeValue) OR $StrSoundEx(Upper(ShortName)) LIKE Upper($StrLikeValue) ";
        $strWhere .= "\n";
        //                $strWhere = $strWhere."OR $StrSoundEx(SurName) LIKE $StrLikeValue ";
        $strWhere = $strWhere."OR $StrSoundEx(Upper(WorkEmailAddress)) LIKE Upper($StrLikeValue) OR $StrSoundEx(Upper(HomeEmailAddress)) LIKE Upper($StrLikeValue) ";
        $strWhere .= "\n";
        $strWhere = $strWhere."OR $StrSoundEx(Upper(ResidentialStreetName)) LIKE Upper($StrLikeValue) OR $StrSoundEx(Upper(PostalAddressLine1)) LIKE Upper($StrLikeValue) ";
        $strWhere .= "\n";
        $strWhere = $strWhere."OR $StrSoundEx(Upper(PostalAddressLine2)) LIKE Upper($StrLikeValue) OR $StrSoundEx(Upper(ResidentialSuburb)) LIKE Upper($StrLikeValue) ";
        $strWhere .= "\n";
        $strWhere = $strWhere."OR $StrSoundEx(Upper(PostalAddressSuburb)) LIKE Upper($StrLikeValue) OR $StrSoundEx(HomePhoneNumber) LIKE $StrLikeValue ";
        $strWhere .= "\n";
        $strWhere = $strWhere."OR $StrSoundEx(WorkPhoneNumber) LIKE Upper($StrLikeValue) OR $StrSoundEx(WorkFaxNumber) LIKE $StrLikeValue ";
        $strWhere .= "\n";
        $strWhere = $strWhere."OR $StrSoundEx(HomeFaxNumber) LIKE $StrLikeValue OR $StrSoundEx(HomeFaxNumber) LIKE $StrLikeValue ";
        $strWhere .= "\n";
        $strWhere = $strWhere."OR $StrSoundEx(WorkFaxNumber) LIKE $StrLikeValue OR $StrSoundEx($PACTS_cfg->individualtablename.CommentText) LIKE $StrLikeValue ";
        $strWhere .= "\n";
        $strWhere = $strWhere."OR $StrSoundEx(Upper($PACTS_cfg->familytablename.CommentText)) LIKE $StrLikeValue OR $StrSoundEx(Upper(".$PACTS_cfg->worktypetablename.".Description)) LIKE Upper($StrLikeValue) ";
        $strWhere .= "\n";
        $bNoTickBoxes = TRUE;
    } else {
        $bNoTickBoxes = FALSE;
    }
    $sql = "";
    $sql=$sql."SELECT *, ".$PACTS_cfg->worktypetablename.".Description as worktypedesc, SOUNDEX('$searchstring') as SXss, $StrSoundEx(Concat(FirstName, ' ', Surname)) AS SSFullname, ";
    $sql=$sql."\n";
    $sql=$sql."$StrSoundEx(Surname) AS SSSurname, $StrSoundEx(FirstName) AS SSFirstName, $StrSoundEx(ShortName) AS SSShortName, $StrSoundEx(WorkEmailAddress) AS SSWEA, ";
    $sql=$sql."\n";
    $sql=$sql."$StrSoundEx(HomeEmailAddress) AS SSHEA, $StrSoundEx(ResidentialStreetName) AS SSRStreetName, $StrSoundEx(PostalAddressLine1) AS SSPALn1, ";
    $sql=$sql."\n";
    $sql=$sql."$StrSoundEx(PostalAddressLine2) AS SSPALn2, $StrSoundEx(ResidentialSuburb) AS SSSuburb, $StrSoundEx(PostalAddressSuburb) AS SSPASuburb, ";
    $sql=$sql."\n";
    $sql=$sql."$StrSoundEx(HomePhoneNumber) AS SSHPhNum, $StrSoundEx(HomeFaxNumber) AS SSHFaxNum, $StrSoundEx(WorkPhoneNumber) AS SSWPhNum, ";
    $sql=$sql."\n";
    $sql=$sql."$StrSoundEx(WorkFaxNumber) AS SSWFaxNum, $StrSoundEx($PACTS_cfg->individualtablename.CommentText) AS SSICmmntTxt, ";
    $sql=$sql."\n";
    $sql=$sql."$StrSoundEx($PACTS_cfg->familytablename.CommentText) AS SSFCmmntTxt, $PACTS_cfg->familytablename.CommentText AS Fmly_CommentText, ";
    $sql=$sql."\n";
    $sql=$sql."$PACTS_cfg->individualtablename.CommentText AS Indv_CommentText ";
    $sql=$sql."\n";
    $sql=$sql."FROM ($PACTS_cfg->individualtablename ";
    $sql=$sql."\n";
    $sql=$sql."INNER JOIN $PACTS_cfg->familytablename ON $PACTS_cfg->individualtablename.FamilyId = $PACTS_cfg->familytablename.FamilyId) ";
    $sql=$sql."\n";
    $sql=$sql."LEFT JOIN ".$PACTS_cfg->worktypetablename." ON $PACTS_cfg->individualtablename.worktypeCode = ".$PACTS_cfg->worktypetablename.".worktypeCode ";
    $sql=$sql."\n";
    $sql=$sql."WHERE $strWhere ORDER BY Surname ASC";

    //echo "<p>".str_replace("\n", "<br>\n", $sql)." <p>";

    $result = mysql_query($sql,$PACTS_cfg->dblink);
    $totalrecords = mysql_num_rows($result);

    if ($totalrecords == 1)
    {

        $myrow = mysql_fetch_array($result);
        $IndividualId = $myrow["IndividualId"];
        $URL = 'index.php?view=Indv_view&IndividualId='.$IndividualId;

        echo '<script type="text/javascript">'."\n";
        echo '<!--'."\n";
        echo 'window.location = "'.$URL.'"'."\n";


        echo '//-->'."\n";
        echo '</script>'."\n";
        exit;
    }

    echo '<p class="mediumtxt">Number of results = '.$totalrecords.'</p><br />'."\n";
    echo '<hr width="99%">'."\n";
    if($totalrecords > 0) {
        echo '<table border="0"><tr><td align="center"><p class="mediumtxt">Individual</p></td><td align="center"><p class="mediumtxt">Matched On</p></td><td>&nbsp;</td></tr>'."\n";
        echo "";
    }
    //	echo "number of results: $resultsnumber";

    $alternate = "2";
    $searchstring_orig = $searchstring;
    while ($myrow = mysql_fetch_array($result))
    {
        // reset search string
        $searchstring = $searchstring_orig ;

        $IndividualId = $myrow["IndividualId"];
        $FamilyId = $myrow["FamilyId"];
        $Fullname = $myrow["FirstName"]." ".$myrow["Surname"];
        $Surname = $myrow["Surname"];
        $FirstName = $myrow["FirstName"];
        $ShortName = $myrow["ShortName"];
        $WorkEmail = $myrow["WorkEmailAddress"];
        $HomeEmail = $myrow["HomeEmailAddress"];
        $ResidentialStreetName = $myrow["ResidentialStreetName"];
        $ResidentialStreetNum = $myrow["ResidentialStreetNum"];
        $ResidentialStreetTypeCode = $myrow["ResidentialStreetTypeCode"];

        $PostalAddressLine1 = $myrow["PostalAddressLine1"];
        $PostalAddressLine2 = $myrow["PostalAddressLine2"];
        $ResidentialSuburb = $myrow["ResidentialSuburb"];
        $PostalAddressSuburb = $myrow["PostalAddressSuburb"];
        $Indv_CommentText =  $myrow["Indv_CommentText"];
        $Fmly_CommentText =  $myrow["Fmly_CommentText"];
        $worktype = $myrow["worktypedesc"];
        //$StrSoundEx(worktype.Description)

        // work out what field the match was on
        $searchMatchOn = "";
        if (is_null($cbSoundsLike ))
        {
            // remove % from $searchstring
            while( strpos($searchstring,"%")) {
                $tmp1 = substr($searchstring,0,strpos($searchstring,"%"));
                $tmp2 = substr($searchstring,strpos($searchstring,"%")+1);
                $searchstring = trim($tmp1)."(.*)".trim($tmp2);
            }
            while( strpos($searchstring," ")) {
                $tmp1 = substr($searchstring,0,strpos($searchstring," "));
                $tmp2 = substr($searchstring,strpos($searchstring," ")+1);
                $searchstring = trim($tmp1)."(.*)".trim($tmp2);
            }
            $searchstring = "(.*)$searchstring(.*)";

            //echo "searchstring : $searchstring<br>";
            $bMatch = false;
            // not sounds like, i.e. Wildcard
            if ((!is_null($cbFirstName) and !is_null($cbSurname)) or $bNoTickBoxes ){
                if (ereg(strtolower ($searchstring),  strtolower ($FirstName." ".$Surname))) {
                    if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                    $searchMatchOn = $searchMatchOn." $FirstName $Surname";}
                $bMatch = true;
            }
            if (!$bMatch){
                if (!is_null($cbSurname) or $bNoTickBoxes ){
                    if (ereg(strtolower ($searchstring),  strtolower ($Surname))) {
                        if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                        $searchMatchOn = $searchMatchOn." $Surname";}
                    if (ereg(strtolower ($searchstring),  strtolower ($Fullname))) {
                        if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                        $searchMatchOn = $searchMatchOn." $Fullname";}}

            }
            if (!$bMatch){
                if (!is_null($cbFirstName) or $bNoTickBoxes ){
                    if (ereg(strtolower ($searchstring),  strtolower ($FirstName))) {
                        if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                        $searchMatchOn = $searchMatchOn." $FirstName";}}


            }
            if (!$bMatch){


                if (!is_null($cbworktype) or $bNoTickBoxes ){
                    if (ereg(strtolower ($searchstring),  strtolower ($worktype))) {
                        if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                        $searchMatchOn = $searchMatchOn." $worktype";
                    }
                }
            }
            if (!$bMatch){
                if (!is_null($cbComments) or $bNoTickBoxes ){
                    if (ereg(strtolower ($searchstring),  strtolower ($Indv_CommentText))) {
                        if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                        $searchMatchOn = $searchMatchOn." $Indv_CommentText";
                    }
                    if (ereg(strtolower ($searchstring),  strtolower ($Fmly_CommentText))) {
                        if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                        $searchMatchOn = $searchMatchOn." $Fmly_CommentText";
                    }
                }
            }
            if (!$bMatch){
                if (!is_null($cbShortName) or $bNoTickBoxes ){
                    if (ereg(strtolower ($searchstring),  strtolower ($ShortName))) {
                        if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                        $searchMatchOn = $searchMatchOn." $ShortName";
                    }}
            }
            if (!$bMatch){
                if (!is_null($cbEmail) or $bNoTickBoxes ){
                    if (ereg(strtolower ($searchstring),  strtolower ($WorkEmail))) {
                        if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                        $searchMatchOn = $searchMatchOn.' <a class="navbartext" title="Send email to '.$Fullname.' ('.$WorkEmail.')" href="mailto:'.$WorkEmail.'" rel="external">'.$WorkEmail.'</a>'."\n";
                    }
                    if (ereg(strtolower ($searchstring),  strtolower ($HomeEmail))) {
                        if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                        $searchMatchOn = $searchMatchOn.' <a class="navbartext" title="Send email to '.$Fullname.' ('.$HomeEmail.')" href="mailto:'.$HomeEmail.'" rel="external">'.$HomeEmail.'</a>'."\n";
                    }}
            }
            if (!$bMatch){
                if (!is_null($cbStreetName) or $bNoTickBoxes ){
                    if (ereg(strtolower ($searchstring),  strtolower ($ResidentialStreetName))) {
                        if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                        $searchMatchOn = $searchMatchOn." $ResidentialStreetNum $ResidentialStreetName $ResidentialStreetTypeCode";
                    }
                    if (ereg(strtolower ($searchstring),  strtolower ($PostalAddressLine1))) {
                        if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                        $searchMatchOn = $searchMatchOn." $PostalAddressLine1";
                    }
                    if (ereg(strtolower ($searchstring),  strtolower ($PostalAddressLine2))) {
                        if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                        $searchMatchOn = $searchMatchOn." $PostalAddressLine2";
                    }}
            }
            if (!$bMatch){
                if (!is_null($cbSuburb) or $bNoTickBoxes ){
                    if (ereg(strtolower ($searchstring),  strtolower ($ResidentialSuburb))) {
                        if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                        $searchMatchOn = $searchMatchOn." $ResidentialSuburb";
                    }
                    if (ereg(strtolower ($searchstring),  strtolower ($PostalAddressSuburb))) {
                        if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                        $searchMatchOn = $searchMatchOn." $PostalAddressSuburb";
                    }}
            }
        } else
        {
            // with sounds like
            if (!is_null($cbSurname) or $bNoTickBoxes ){
                if ($myrow["SXss"]  == @$myrow["SSSurname"]) {
                    if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                    $searchMatchOn = $searchMatchOn." $Surname";}
                if ($myrow["SXss"]  == @$myrow["SSFullname"]) {
                    if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                    $searchMatchOn = $searchMatchOn." $Fullname";}}
            if (!is_null($cbFirstName) or $bNoTickBoxes ){
                if ($myrow["SXss"]  == @$myrow["SSFirstName"]) {
                    if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                    $searchMatchOn = $searchMatchOn." $FirstName";}}
            if (!is_null($cbShortName) or $bNoTickBoxes ){
                if ($myrow["SXss"]  == @$myrow["SSShortName"]) {
                    if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                    $searchMatchOn = $searchMatchOn." $ShortName";
                }}
            if (!is_null($cbEmail) or $bNoTickBoxes ){
                if ($myrow["SXss"]  == @$myrow["SSWEA"]) {
                    if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                    $searchMatchOn = $searchMatchOn." $WorkEmail";
                }
                if ($myrow["SXss"]  == @$myrow["WWHEA"]) {
                    if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                    $searchMatchOn = $searchMatchOn." $HomeEmail";
                }}
            if (!is_null($cbStreetName) or $bNoTickBoxes ){
                if ($myrow["SXss"]  == $myrow["SSRStreetName"]) {
                    if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                    $searchMatchOn = $searchMatchOn." $ResidentialStreetNum $ResidentialStreetName $ResidentialStreetTypeCode";
                }
                if ($myrow["SXss"]  == @$myrow["SSPALn1"]) {
                    if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                    $searchMatchOn = $searchMatchOn." $PostalAddressLine1";
                }
                if ($myrow["SXss"]  == @$myrow["SSPALn2"]) {
                    if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                    $searchMatchOn = $searchMatchOn." $PostalAddressLine2";
                }}
            if (!is_null($cbSuburb) or $bNoTickBoxes ){
                if ($myrow["SXss"]  == @$myrow["SSSuburb"]) {
                    if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                    $searchMatchOn = $searchMatchOn." $ResidentialSuburb";
                }
                if ($myrow["SXss"]  == @$myrow["SSPASuburb"]) {
                    if (strlen($searchMatchOn) > 0 ) { $searchMatchOn .= ", ";}
                    $searchMatchOn = $searchMatchOn." $PostalAddressSuburb";
                }}
        }

        $printXX =  "$Surname, $FirstName </td><td  class=\"navbartext\" ><i>(".trim($searchMatchOn).")</i>";
        //			echo "<td>";
        //			echo "<table><tr bgcolor=$color>";

        echo $PACTS_cfg->getIndvNavBar($IndividualId, $FamilyId, TRUE, TRUE, TRUE, "Fmly_view","",TRUE,$printXX);

        //echo"</tr></table>";
        echo "</tr>";
    } // end while

    if($totalrecords > 0)
    {
        echo "</tr></table>";
        echo "<p>Look <a href='index.php?view=Indv_az_index&amp;'>alphabetically</a> or <a href='".$_SERVER['PHP_SELF']."'>search again</a></p>";
    }

}


//else
//	{
//}

?>
